# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>
# Contributor: Biswapriyo Nath <nathbappai@gmail.com>

_realname=spirv-headers
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
epoch=1
pkgver=1.3.236.0
pkgrel=1
pkgdesc='Machine-readable files for the SPIR-V Registry (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://www.khronos.org/registry/spir-v/'
license=('spdx:MIT')
groups=("${MINGW_PACKAGE_PREFIX}-vulkan-devel")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
# From https://github.com/KhronosGroup/SPIRV-Tools/blob/master/DEPS
# _commit="b42ba6d92faf6b4938e6f22ddd186dbdacc98d78"
# "${_realname}"::"git+https://github.com/KhronosGroup/SPIRV-Headers#commit=${_commit}"
source=(https://github.com/KhronosGroup/SPIRV-Headers/archive/refs/tags/sdk-${pkgver}/${_realname}-${pkgver}.tar.gz)
sha512sums=('0faf13ba60a0b28081dfdc90a08eadb03c848da1f6e5ec5df436c6c470bc7f986c2663bbbf4478d9fb9f16fc7083313f6efe9f4db282844a40754c125876bfe7')

build() {
  [[ -d ${srcdir}/build-${MSYSTEM} ]] && rm -rf ${srcdir}/build-${MSYSTEM}
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../SPIRV-Headers-sdk-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd ${srcdir}/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./

  install -Dm644 ${srcdir}/SPIRV-Headers-sdk-${pkgver}/README.md ${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md
  install -Dm644 ${srcdir}/SPIRV-Headers-sdk-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
